package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbContentCategoryMapper;
import com.dongdongshop.pojo.*;
import com.dongdongshop.service.TbContentCategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class TbContentCategoryServiceImpl implements TbContentCategoryService {

    //注入mapper
    @Autowired
    private TbContentCategoryMapper tbContentCategoryMapper;

    //查询全部广告分类列表(要求分页)
    @Override
    public PageResult<TbContentCategory> TbContentCategoryshowall(Integer pageNum, Integer pageSize, String name) {
        PageHelper.startPage(pageNum, pageSize);
        List<TbContentCategory> tbSpecifications = null;
        if ("".equals(name) || name == null) {
            tbSpecifications = tbContentCategoryMapper.selectByExample(null);
        } else {
            TbContentCategoryExample te = new TbContentCategoryExample();
            TbContentCategoryExample.Criteria criteria = te.createCriteria();
            criteria.andNameLike("%" + name + "%");
            tbSpecifications = tbContentCategoryMapper.selectByExample(te);
        }
        PageInfo<TbContentCategory> info = new PageInfo(tbSpecifications);
        return new PageResult<TbContentCategory>(pageNum, pageSize, info.getTotal(), info.getList(), info.getPages());
    }

    //添加广告分类
    @Override
    public void addTbContentCategory(TbContentCategory contentCategory) {
        tbContentCategoryMapper.insertSelective(contentCategory);
    }

    //回显单个广告分类数据
    @Override
    public TbContentCategory showecho(Long id) {
        return tbContentCategoryMapper.selectByPrimaryKey(id);
    }

    //修改单个数据
    @Override
    public void updateTbContentCategory(TbContentCategory tbBrand) {
        tbContentCategoryMapper.updateByPrimaryKeySelective(tbBrand);
    }

    //删除单个数据
    @Override
    public void deleteTbContentCategory(Long id) {
        tbContentCategoryMapper.deleteByPrimaryKey(id);
    }

    //删除多个数据
    @Override
    public void deleteallTbContentCategory(List<Long> ids) {
        TbContentCategoryExample te = new TbContentCategoryExample();
        TbContentCategoryExample.Criteria criteria = te.createCriteria();
        criteria.andIdIn(ids);
        tbContentCategoryMapper.deleteByExample(te);
    }

    //查询全部广告分类列表(用于回显)
    @Override
    public List<TbContentCategory> TbContentCategoryshow() {
        return tbContentCategoryMapper.selectByExample(null);
    }
}